﻿@model ConferenceRoleMasterModel
@{
	ViewBag.Title = Resources.ConferenceRoleMaster + ConstValues.strDash + ViewBag.ConferenceName;
}
<div id="menuBar" style="height:35px;">
	<div style="float: left; padding: 5px 5px; font-weight: bold; text-align: left;">
		@Resources.RoleName：<input id="selRoleName" class="easyui-textbox" style="height:27px; width:200px;" />&nbsp;&nbsp;
		<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" onclick="searchData();">@Resources.Search</a>&nbsp;&nbsp;
		@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceRoleMaster, RoleType.添加))
		{
			<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-add" onclick="addData();" plain="true">@Resources.Create</a>
		}
	</div>
	<div class="clear"></div>
</div>
<div id="dataGrid"></div>

@section bodyParts {
<div id="detailWindow" class="easyui-window"
	title="@Resources.ConferenceRoleMaster" data-options="closed:true,minimizable:false,iconCls:'icon-save'"
	style="width:1200px; display:none;">
	<div class="main">
		<div class="box clearfix">
			<h3 id="detailWindowTitle" class="tit01"></h3>
			<form id="frmDetail" method="post">
				@Html.AntiForgeryToken()
				<table width="100%" height="100%" id="tblDetail" cellpadding="0" cellspacing="1" border="0" class="tastyle01">
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.RoleName：</td>
						<td style="text-align: left;" class="w2 c2">
							<input type="hidden" id="hidID" name="Id" />
							<input type="hidden" id="hidConferenceId" name="conferenceId" />
							<input id="txtRoleName" name="roleName" class="easyui-textbox" style="height:27px; width:300px;" data-options="required:true,validType:['length[1,100]']" />
						</td>
						<td style="text-align: right;" class="w1 c1"></td>
						<td style="text-align: left;" class="w2 c2"></td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.Status：</td>
						<td style="text-align: left;" class="w2 c4">
							<select id="ddlStatus" name="status" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,required:true,panelHeight:'auto'">
								<option value="@ConstValues.Status.正常">@Resources.Normal</option>
								<option value="@ConstValues.Status.暂停">@Resources.Pause</option>
							</select>
						</td>
						<td style="text-align: right;" class="w1 c3">@Resources.Sort：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="txtSort" name="sort" class="easyui-numberbox" style="height:27px; width:300px;" data-options="validType:['length[1,100]']" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.Remark：</td>
						<td style="text-align: left;" class="w2 c2" colspan="3">
							<input id="txtRemark" name="remark" class="easyui-textbox" style="height:50px; width:892px;" data-options="multiline:true, validType:['length[1,1000]']" />
						</td>
					</tr>
				</table>
			</form>
			<div class="btnDiv">
				<input type="hidden" id="hdnWindowType" />
				<input type="button" class="gbtn" onclick="saveData();" value="@Resources.Save" />&nbsp;&nbsp;
				<input type="button" class="rbtn" onclick="$('#detailWindow').window('close');" value="@Resources.Cancel" />
			</div>
		</div>
	</div>
</div>
<div id="actionWindow" class="easyui-window"
	title="@Resources.ConferenceRoleMaster" data-options="closed:true,minimizable:false,maximizable:false,iconCls:'icon-save'"
	style="width:1200px; display:none;">
	<div class="main">
		<div class="box clearfix">
			<h3 id="actionWindowTitle" class="tit01"></h3>
			<form id="actionDetail" method="post">
				@Html.AntiForgeryToken()
				<table width="100%" height="100%" id="actionTblDetail" cellpadding="0" cellspacing="1" border="0" class="tastyle01">
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.RoleName：</td>
						<td style="text-align: left;" class="w2 c2">
							<input type="hidden" id="actConferenceId" name="actConferenceId" />
							<input type="hidden" id="hidRoleId" name="roleId" />
							<input id="tRoleName" class="easyui-textbox" style="height:27px; width:300px;" disabled />
						</td>
						<td style="text-align: right;" class="w1 c1">@Resources.AuthorityName：</td>
						<td style="text-align: left;" class="w2 c2">
							<select id="ddlAction" name="actionId" class="easyui-combobox" style="height:27px; width:220px;" data-options="editable:false,required:true"></select>
							&nbsp;&nbsp;<input type="button" class="gbtn" onclick="saveActionData();" value="@Resources.Create" />
						</td>
					</tr>
				</table>
			</form>
			<div id="actionGrid"></div>
		</div>
	</div>
</div>
}

@section Scripts {
<script>
	common.setCurrentMenu("ConferenceRoleMaster");
	common.setCurrentParentMenu("#menu_a7");

	$(function () {
		$("#selRoleName").textbox("textbox").bind("keydown", function (e) {
			if (e.keyCode == 13) {
				searchData()
			}
		});
		$("#hidConferenceId").val("@Model.ConferenceId");
		$("#dataGrid").datagrid({
			url: "@Url.Action(nameof(ConferenceRoleMasterController.GetData),
					nameof(ConferenceRoleMasterController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
			method: "get",
			singleSelect: true,
			fitColumns: true,
			width: $(window).width() - 285,
			height: $(window).height() - 158,
			nowrap: false,
			pagination: true,
			pageSize: @ConstValues.DefaultGridRows,
			striped: true,
			toolbar: "#toolBar",
			pageSize: 100, 
			pageList: [100, 200, 300, 400, 500],
			columns: [[
				{ field: "id", hidden: true },
				@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) ||
					Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceRoleMaster, RoleType.修改) ||
					Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceRoleMaster, RoleType.删除))
				{
					<text>
					{
					        field: "operate", title: "@Resources.Operate", align: "center", width: 200,
					        formatter: function(value, rec) {
					        	var strInfo = "";
						        var tmp = rec.roleName == null ? "" : rec.roleName.replace(new RegExp("'",'g'),"’").replace(new RegExp('"','g'),"“");
					        	@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceRoleMaster, RoleType.修改))
						        {
								<text>
					        		strInfo += "<a href='#' style='color:#FF8C00;font-weight:bold;text-decoration:underline;' onclick='actionData(\""
										+ rec.id + "\",\"" + tmp + "\")'>@Resources.ModifyRight</a>";
					        		strInfo += "&nbsp;|&nbsp;";
					        		strInfo += "<a href='#' style='color:#66CDAA;font-weight:bold;text-decoration:underline;' onclick='editData(\""
									+ rec.id + "\")'>@Resources.Modify</a>";
					        		</text>
						        }
					        	@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceRoleMaster, RoleType.删除))
							{
								<text>
					        		if (strInfo != "") {
					        			strInfo += "&nbsp;|&nbsp;";
					        		}
					        		strInfo += "<a href='#' style='color:#DC143C;font-weight:bold;text-decoration:underline;' onclick='deleteData(\""
									+ rec.id + "\",\"" + tmp + "\")'>@Resources.Delete</a>";
					        		</text>
							}
					        	return strInfo;
					        }
					},
					</text>
				}
				{ field: "roleName", title: "@Resources.RoleName", align: "center", sortable: true, width: 150 },
				{
					field: "status", title: "@Resources.Status", align: "center", sortable: true, width: 100,
					formatter: function(value, rec) {
						if (value=="@ConstValues.Status.正常") {
							return "@Resources.Normal"
						} else {
							return "@Resources.Pause"
						}
					}
				},
				{ field: "sort", title: "@Resources.Sort", align: "center", sortable: true, width: 100 },
				{ field: "remark", title: "@Resources.Remark", align: "center",  sortable: true, width: 200 },
				{ field: "creator", title: "@Resources.Creator", align: "center",  sortable: true, width: 100 },
				{ field: "createIP", title: "@Resources.CreateIP", align: "center",  sortable: true, width: 100 },
				{ field: "createDate", title: "@Resources.CreateDate", align: "center",  sortable: true, width: 100 },
			]],
			onBeforeLoad: function(param) {
				param.conferenceId = $("#hidConferenceId").val();
				param.random = Math.random();
			},
		});

		$(window).resize(function () {
			$("#dataGrid").datagrid("resize", {
				width: $(window).width() - 285,
				height: $(window).height() - 158
			});
		});

		$("#detailWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			top: ($(window).height() - 600) * 0.5
		});

		$("#actionWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			top: ($(window).height() - 600) * 0.5
		});
	});

	function searchData() {
		$("#dataGrid").datagrid("load", {
			SelRoleName: $("#selRoleName").textbox("getValue")
		});
	}

	function addData() {
		$("#hdnWindowType").val("add");
		$("#detailWindowTitle").text("@Resources.Create");
		$("#hidID").val("");
		$("#txtRoleName").textbox("setValue", "");
		$("#ddlStatus").combobox("setValue", "@ConstValues.Status.正常");
		$("#txtSort").numberbox("setValue", @ConstValues.DefaultSort);
		$("#txtRemark").textbox("setValue", "");
		$("#detailWindow").window("open");
	}

	function editData(id) {
		var url = "@Url.Action(nameof(ConferenceRoleMasterController.GetEditData),
				nameof(ConferenceRoleMasterController).GetControllerName())" + "/" + id;
		$.get(url, null, function (data, textStatus, jqXHR) {
			if (data.result == "@ConstValues.AjaxFailResult") {
				common.showError(data.message);
				$("#dataGrid").datagrid("reload");
			} else {
				$("#hdnWindowType").val("edit");
				$("#detailWindowTitle").text("@Resources.Modify");
				$("#hidID").val(id);
				$("#txtRoleName").textbox("setValue", data.data.roleName);
				$("#ddlStatus").combobox("setValue", data.data.status);
				$("#txtSort").numberbox("setValue", data.data.sort);
				$("#txtRemark").textbox("setValue", data.data.remark);
				$("#detailWindow").window("open");
			}
		});
	}

	function deleteData(id, name) {
		var confirmMessage = "@Resources.CfmDelete";
		confirmMessage = confirmMessage.replace(/\{0\}/g, name);
		$.messager.confirm("@Resources.Delete", confirmMessage, function (r) {
			if (r) {
				$("#hidID").val(id);
				$.post("@Url.Action(nameof(ConferenceRoleMasterController.Delete),
						nameof(ConferenceRoleMasterController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
					$("#frmDetail").serialize(),
					function(data, textStatus, jqXHR) {
						if (data.result == "@ConstValues.AjaxFailResult") {
							common.showError(data.message);
						} else {
							common.showSuccess(data.message, true);
							$("#dataGrid").datagrid("reload");
						}
					}
				);
			}
		});
	}

	function saveData() {
		var isValid = $("#frmDetail").form("validate");

		if (isValid) {
			$.messager.confirm("@Resources.Save", "@Resources.CfmSave", function (r) {
				if (r) {
					var loading = layer.load(0,  {
						shade: [0.4,"#fff"]
					});
					switch ($("#hdnWindowType").val())
					{
						case "add":
							$.post("@Url.Action(nameof(ConferenceRoleMasterController.Create),
									nameof(ConferenceRoleMasterController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
								$("#frmDetail").serialize(),
								function(data, textStatus, jqXHR) {
									layer.close(loading);
									if (data.result == "@ConstValues.AjaxFailResult") {
									    	common.showError(data.message);
									} else {
									    	common.showSuccess(data.message, true);
									    	$("#detailWindow").window("close");
									    	$("#dataGrid").datagrid("reload");
									}
								}
							);
							break;
						case "edit":
							$.post("@Url.Action(nameof(ConferenceRoleMasterController.Modify),
									nameof(ConferenceRoleMasterController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
									$("#frmDetail").serialize(),
								function(data, textStatus, jqXHR) {
									layer.close(loading);
									if (data.result == "@ConstValues.AjaxFailResult") {
									    	common.showError(data.message);
									} else {
									    	common.showSuccess(data.message, true);
									    	$("#detailWindow").window("close");
									    	$("#dataGrid").datagrid("reload");
									}
								}
							);
							break;
					}
				}
			});
		}
	}

	function actionData(id, roleName) {
		$("#actionGrid").datagrid({
			url: "@Url.Action(nameof(ConferenceRoleMasterController.GetActionData),
					nameof(ConferenceRoleMasterController).GetControllerName())"+"?roleId="+id,
			method: "get",
			fitColumns: true,
			height: 478,
			nowrap: false,
			pageSize: @ConstValues.DefaultGridRows,
			striped: true,
			toolbar: "#actionToolBar",
			columns: [[
				{
					field: "operate", title: "@Resources.Operate", align: "center", width: 150,
					formatter: function(value, rec) {
			    			var strInfo = "";
						var tmp = rec.actionName == null ? "" : rec.actionName.replace(new RegExp("'",'g'),"’").replace(new RegExp('"','g'),"“");
			    			strInfo += "<a href='#' style='color:#DC143C;font-weight:bold;text-decoration:underline;' onclick='deleteActionData(\""
								+ rec.id + "\",\"" + tmp + "\")'>@Resources.Delete</a>";
			    			return strInfo;

					}
				},
				{ field: "roleId", hidden: true },
				{ field: "roleName", title: "@Resources.RoleName", align: "center", sortable: true, width: 150 },
				{ field: "actionName", title: "@Resources.AuthorityName", align: "center", width: 150 },

			]],
			onBeforeLoad: function(param) {
				param.conferenceId = $("#hidConferenceId").val();
				param.random = Math.random();
			},
		});

		$("#tRoleName").textbox("setValue",roleName);
		$("#actionWindowTitle").text("@Resources.ModifyRight");
		var orgCount = 0;
		$("#ddlAction").combobox({
			editable: false,
			required: true,
			multiple:true,
			valueField: "id",
			textField: "actionName",
			url: "@Url.Action(nameof(ConferenceRoleMasterController.GetAction),
					nameof(ConferenceRoleMasterController).GetControllerName())",
			onBeforeLoad: function(param) {
				param.conferenceId = $("#hidConferenceId").val();
				param.random = Math.random();
			},
			onLoadSuccess: function(data) {
				orgCount = data.length;
			},
			onShowPanel: function () {
				if (orgCount < 10) {
					$(this).combobox("panel").height("auto");
				} else {
					$(this).combobox("panel").height(200);
				}
			}
		});
		$("#hidRoleId").val(id);

		$("#actionWindow").window("open");
	}

	function saveActionData() {
		var isValid = $("#actionDetail").form("validate");
		$("#actConferenceId").val("@Model.ConferenceId");
		if (isValid) {
			$.messager.confirm("@Resources.Save", "@Resources.CfmSave", function (r) {
				if (r) {
					var loading = layer.load(0,  {
						shade: [0.4,"#fff"]
					});
					$.post("@Url.Action(nameof(ConferenceRoleMasterController.CreateAction),
							nameof(ConferenceRoleMasterController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
						$("#actionDetail").serialize(),
						function(data, textStatus, jqXHR) {
							layer.close(loading);
							if (data.result == "@ConstValues.AjaxFailResult") {
								common.showError(data.message);
							} else {
								common.showSuccess(data.message, true);
								$("#actionGrid").datagrid("reload");
								$("#dataGrid").datagrid("reload");
								$("#ddlAction").combobox("clear");
							}
						}
					);
				}
			});
		}
	}

	function deleteActionData(id, name) {
		var confirmMessage = "@Resources.CfmDelete";
		confirmMessage = confirmMessage.replace(/\{0\}/g, name);
		$.messager.confirm("@Resources.Delete", confirmMessage, function (r) {
			if (r) {
				$("#hidID").val(id);
				$.post("@Url.Action(nameof(ConferenceRoleMasterController.DeleteAction),
						nameof(ConferenceRoleMasterController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
					$("#frmDetail").serialize(),
					function(data, textStatus, jqXHR) {
						if (data.result == "@ConstValues.AjaxFailResult") {
							common.showError(data.message);
						} else {
							common.showSuccess(data.message, true);
							$("#actionGrid").datagrid("reload");
							$("#dataGrid").datagrid("reload");
						}
					}
				);
			}
		});
	}
</script>
}